
<script language="javascript">
function initializeBody(){      	
      	try {
			// Seteo de proyecciones
			projection = new OpenLayers.Projection("EPSG:900913"); 
	       	displayProjection = new OpenLayers.Projection("EPSG:4326");
	
			mapOptions = {
	                projection: projection,
	                displayProjection: displayProjection,
	                units: "km",
	                numZoomLevels: 19,
	                maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
	        };
			
			//asegurar la carga de GMAPS con REFRESH la primera vez que ingrese.
			
	        map = new OpenLayers.Map('map_canvas', mapOptions);

			var gmap = new OpenLayers.Layer.Google(
	                "Calles", 
	                {type: G_NORMAL_MAP, 'sphericalMercator': true, MAX_ZOOM_LEVEL:17}
	        	);
	            var gsat = new OpenLayers.Layer.Google(
	                "Satelite",
	                {type: G_SATELLITE_MAP, 'sphericalMercator': true}
	            );
				var ghyb = new OpenLayers.Layer.Google(
	                "Hibrido",
	                {type: G_HYBRID_MAP, 'sphericalMercator': true}
	            );
				var gphy = new OpenLayers.Layer.Google(
	                "Fisico",
	                {type: G_PHYSICAL_MAP, 'sphericalMercator': true}
	            );
	 			
	            map.addLayers([gmap, gsat, ghyb, gphy]);
				map.setBaseLayer(gmap);
			
			//selector de tipo de mapa
			var oldExtent = null;
			var oldProjection = null;
			var oldBaseLayer = null;
			var setOldValues=function(){
				oldExtent = null;
				oldProjection = null;
				oldBaseLayer = null;
				if (map.baseLayer) { 
		            oldExtent = map.baseLayer.getExtent(); 
	 		        oldProjection = map.getProjectionObject();
					oldBaseLayer = map.baseLayer; 
	        	} 			
			};
			
			var recenter=function(newBaseLayer){	
				//map.render(mapCanvas);
				map.updateSize();
				//map.render(mapCanvas); //lo repito por bug en eventos para ie 8
				if(oldBaseLayer!=newBaseLayer){
					var newCenter = (oldExtent) ? oldExtent.getCenterLonLat() : map.getCenter();
	 		        var newExtent = oldExtent.clone(); 	                         
	                // Convert centre point to new layer projection - so we can 
	                // maintain roughly the same view 
	                var newProjection = map.getProjectionObject(); 
	                if(!oldProjection.equals(newProjection)) { 
	                    newCenter.transform(oldProjection, newProjection); 
	                    newExtent.transform(oldProjection, newProjection); 
	                } 
					//the new zoom will either come from the converted old 
	 			    // Extent or from the current resolution of the map 
	 				var newZoom = (newExtent) ? map.getZoomForExtent(newExtent, true) : map.getZoomForResolution(map.resolution, true); 
	                // zoom and force zoom change 
	                map.setCenter(newCenter, newZoom, false, true);
					if(!oldProjection.equals(newProjection)) { 
	 	                // Also convert vector layers - assuming they are in the 
	 	                // same projection as the original baseLayer - we cannot 
	 	                // trust the projection property all the time as it is 
	 	                // used as a shortcut for externalProjection 
	 	                for (var l=0, len=map.layers.length; l < len; l++) { 
	 	                    if(map.layers[l].transform && (typeof map.layers[l].transform == 'function')) { 
	 	                        map.layers[l].transform(oldProjection, newProjection); 
	 	                    } 
	 	                } 
	 	            } 
				}
				collapseMenuBar();
				collapseMenuBar();
			};
			
			var selectMapMenu = new OpenLayers.Control.SelectSwitcher({buttonText:'Mapa', width:'100px'});
			selectMapMenu.addItem('Calles', function(){setOldValues(); map.setBaseLayer(gmap); recenter(gmap);});
			selectMapMenu.addItem('Satelital', function(){setOldValues(); map.setBaseLayer(gsat); recenter(gsat);});
			selectMapMenu.addItem('Hibrido', function(){setOldValues(); map.setBaseLayer(ghyb); recenter(ghyb);});	
			selectMapMenu.addItem('Fisico', function(){setOldValues(); map.setBaseLayer(gphy); recenter(gphy);});		
			map.addControl(selectMapMenu);		
//////////////////////
/*
		  var vMapOptions = new Array();
		  for(var i=0;i<cantMapas;i++){
	        	vMapOptions[i] =  {
		                projection: projection,
		                displayProjection: displayProjection,
		                units: "km",
		                numZoomLevels: 19,
		                maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
		        };
				cMapController.getMapById(i).setMap(new OpenLayers.Map( 'map_canvas'+i, vMapOptions[i] ));
				cMapController.getMapById(i).getMap().addLayers([gmap, gsat, ghyb, gphy]);
				cMapController.getMapById(i).getMap().setBaseLayer(gmap);
				//selector de tipo de mapa
				var oldExtent = null;
				var oldProjection = null;
				var oldBaseLayer = null;
				var setOldValues=function(){
					oldExtent = null;
					oldProjection = null;
					oldBaseLayer = null;
					if (cMapController.getMapActive().getMap().baseLayer) { 
			            oldExtent = cMapController.getMapActive().getMap().baseLayer.getExtent(); 
		 		        oldProjection = cMapController.getMapActive().getMap().getProjectionObject();
						oldBaseLayer = cMapController.getMapActive().getMap().baseLayer; 
		        	} 			
				};
				var recenter=function(newBaseLayer){	
					//map.render(mapCanvas);
					cMapController.getMapActive().getMap().updateSize();
					//map.render(mapCanvas); //lo repito por bug en eventos para ie 8
					if(oldBaseLayer!=newBaseLayer){
						var newCenter = (oldExtent) ? oldExtent.getCenterLonLat() : cMapController.getMapActive().getCenter();
		 		        var newExtent = oldExtent.clone(); 	                         
		                // Convert centre point to new layer projection - so we can 
		                // maintain roughly the same view 
		                var newProjection = cMapController.getMapActive().getMap().getProjectionObject(); 
		                if(!oldProjection.equals(newProjection)) { 
		                    newCenter.transform(oldProjection, newProjection); 
		                    newExtent.transform(oldProjection, newProjection); 
		                } 
						//the new zoom will either come from the converted old 
		 			    // Extent or from the current resolution of the map 
		 				var newZoom = (newExtent) ? cMapController.getMapActive().getMap().getZoomForExtent(newExtent, true) : cMapController.getMapActive().getMap().getZoomForResolution(cMapController.getMapActive().getMap().resolution, true); 
		                // zoom and force zoom change 
		                cMapController.getMapActive().getMap().setCenter(newCenter, newZoom, false, true);
						if(!oldProjection.equals(newProjection)) { 
		 	                // Also convert vector layers - assuming they are in the 
		 	                // same projection as the original baseLayer - we cannot 
		 	                // trust the projection property all the time as it is 
		 	                // used as a shortcut for externalProjection 
		 	                for (var l=0, len = cMapController.getMapActive().getMap().layers.length; l < len; l++) { 
		 	                    if(cMapController.getMapActive().getMap().layers[l].transform && (typeof cMapController.getMapActive().getMap().layers[l].transform == 'function')) { 
		 	                    	cMapController.getMapActive().getMap().layers[l].transform(oldProjection, newProjection); 
		 	                    } 
		 	                } 
		 	            } 
					}
					collapseMenuBar();
					collapseMenuBar();
				};
				
				var selectMapMenu = new OpenLayers.Control.SelectSwitcher({buttonText:'Mapa', width:'100px'});
				selectMapMenu.addItem('Calles', function(){setOldValues(); cMapController.getMapActive().getMap().setBaseLayer(gmap); recenter(gmap);});
				selectMapMenu.addItem('Satelital', function(){setOldValues(); cMapController.getMapActive().getMap().setBaseLayer(gsat); recenter(gsat);});
				selectMapMenu.addItem('Hibrido', function(){setOldValues(); cMapController.getMapActive().getMap().setBaseLayer(ghyb); recenter(ghyb);});	
				selectMapMenu.addItem('Fisico', function(){setOldValues(); cMapController.getMapActive().getMap().setBaseLayer(gphy); recenter(gphy);});		
				cMapController.getMapById(i).getMap().addControl(selectMapMenu);	
	        }
				*/	
      	} catch (ex){
          	alert(ex);
      		URL = "TESTmap2.php?v=" + '<?=$_GET['v']?>' + "&cuenta=" + '<?=$_GET['v']?>' + "&cuentaSelectSegui=" + '<?=$_GET['v']?>' +"&y=" + '<?=$_GET['y']?>' + "&x=" + '<?=$_GET['x']?>' + "&mapType=bykom";
      		window.location = URL;
      	}
}
		
		
function unloadBody(){
		GUnload();
		}
</script>
